// pages/articleDetail/index.js
import {
  getArticle as _getArticle,
  readArticle as _readArticle,
} from '../../config/api'
import { get, post } from '../../utils/request'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    article: '', // 文章详情
    htmlContent: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getArticle(options.id)
    this.readArticle(options.id)
  },
  // 获取文章详情
  getArticle: async function (id) {
    const res = await get(_getArticle + '/' + id, {}, { loading: false })
    if (res.httpStatus === 200) {
      this.setData({
        article: res.data,
        htmlContent: res.data.content,
      })
    }
  },
  // 文章阅读量增加1
  readArticle: async function (id) {
    const res = await post(_readArticle, { articleId: id }, { loading: false })
    if (res.httpStatus === 200) {
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
})
